package com.alibaba.citrus.cr.common.enums.ordercenter;

import com.google.common.collect.Lists;
import lombok.Getter;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

@Getter
public enum ForecastOrderTypeEnum {
    STD_FORECAST("ZQT2", "01", "标准预报订单"),
    REPLENISH_FORECAST("ZQT4", "03", "补货预报订单"),
    GROUP_FORECAST("ZQT", "11", "集团预报订单"),
    ;

    private final String code;
    private final String value;
    private final String desc;

    ForecastOrderTypeEnum(String code, String value, String desc) {
        this.code = code;
        this.value = value;
        this.desc = desc;
    }

    public static ForecastOrderTypeEnum of(String code) {
        return Arrays.stream(ForecastOrderTypeEnum.values()).filter(source -> Objects.equals(code, source.getCode())).findFirst().orElse(null);
    }

    public static String descByCode(String code) {
        ForecastOrderTypeEnum typeEnum = of(code);
        return Objects.nonNull(typeEnum) ? typeEnum.getDesc() : null;
    }

    public static List<String> codes() {
        return Arrays.stream(ForecastOrderTypeEnum.values()).map(ForecastOrderTypeEnum::getCode).collect(Collectors.toList());
    }

    public static ForecastOrderTypeEnum ofByValue(String value) {
        return Arrays.stream(ForecastOrderTypeEnum.values()).filter(source -> Objects.equals(value, source.getValue())).findFirst().orElse(null);
    }

    public static List<String> companyOrderCodes() {
        return Lists.newArrayList(STD_FORECAST.getCode(), REPLENISH_FORECAST.getCode());
    }

    public static List<String> groupOrderCodes() {
        return Lists.newArrayList(GROUP_FORECAST.getCode());
    }
}
